package com.dmz.workflow.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.dmz.workflow.base.BaseServiceImpl;
import com.dmz.workflow.constant.CommonConstants;
import com.dmz.workflow.dao.WorkflowProcessJsonMapper;
import com.dmz.workflow.service.WorkflowProcessJsonService;
import com.dmz.workflow.entity.ProcessJson;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Slf4j
@Service
public class WorkflowProcessJsonServiceImpl extends BaseServiceImpl<WorkflowProcessJsonMapper, ProcessJson> implements WorkflowProcessJsonService {

    @Autowired
    private WorkflowProcessJsonService workflowProcessJsonService;

    @Override
    public ProcessJson getProcessJsonByProcessDefinitionId(String processDefinitionId) {
        LambdaQueryWrapper<ProcessJson> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(ProcessJson::getProcessDefinitionId, processDefinitionId)
                .ne(ProcessJson::getIsDeleted, CommonConstants.DATA_DELETED_STATUS);
        return workflowProcessJsonService.getOne(lambdaQueryWrapper);
    }

    @Override
    public ProcessJson getProcessJsonByProcessNameAndCompanyId(String processDefinitionName, Integer companyId) {
        LambdaQueryWrapper<ProcessJson> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(ProcessJson::getCompanyId, companyId)
                .eq(ProcessJson::getName, processDefinitionName)
                .ne(ProcessJson::getIsDeleted, CommonConstants.DATA_DELETED_STATUS);
        return workflowProcessJsonService.getOne(lambdaQueryWrapper);
    }
}
